package com.bwhx.eruler.service.casdilly.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.casdilly.CasdillyScanData;
import com.bwhx.eruler.bean.casdilly.ClothesType;
import com.bwhx.eruler.bean.casdilly.CasdillyCustomer;
import com.bwhx.eruler.dao.casdilly.CasdillyCustomerDAO;
import com.bwhx.eruler.dao.casdilly.CasdillyScanDataDAO;
import com.bwhx.eruler.service.casdilly.CasdillyCustomerService;

@Service
public class CasdillyCustomerServiceImpl implements CasdillyCustomerService {
	
	@Autowired
	CasdillyCustomerDAO customerDAO;
	
	@Autowired
	CasdillyScanDataDAO casdillyScanDataDAO;

	@Override
	public List<CasdillyCustomer> findByFenchangIDAndCreatorID(String lMIDFenChang, String loginID) {		
		return customerDAO.findByFenchangIDAndCreatorID( lMIDFenChang,  loginID);
	}
	
	
	//新增查询条件 通过分场id和当前登录的用户id查找用户数据
	@Override
	public List<CasdillyCustomer> findUserDataByFenchangIDAndCreatorID(String lMIDFenChang, String loginID) {		
		return customerDAO.findUserDataByFenchangIDAndCreatorID( lMIDFenChang,  loginID);
	}
	

	@Override
	public String addCustomer(CasdillyCustomer customer) {
		return customerDAO.addCustomer(customer);
	}

	@Override
	public int updateCustomerPic(HashMap<String, String> dataMap) {
		return customerDAO.updateCustomerPic(dataMap);
	}

	@Override
	public CasdillyCustomer findByID(String customerID) {
  		return customerDAO.findByID(customerID); 
	}

	
	@Transactional
	@Override
	public void updateCustomer(CasdillyCustomer customer, List<CasdillyScanData> cScanDataList) {
		
 		
 		if(cScanDataList!=null&&cScanDataList.size()!=0){
 			casdillyScanDataDAO.del(customer.getCustomerID());
 			casdillyScanDataDAO.insert(cScanDataList);
 		}
		
		customerDAO.updateCustomer(customer);
		
	}

	@Override
	public CasdillyCustomer get(String customerID) {
		return customerDAO.get(customerID);
	}

	@Override
	public List<CasdillyCustomer> list(Page entity) {
		return 		customerDAO.list(entity);
	}

	@Override
	public Integer count(CasdillyCustomer entity) {
		return 		customerDAO.count(entity);

	}

	@Override
	public void insert(CasdillyCustomer entity) {
		customerDAO.insert(entity);
	}

	@Override
	public void update(CasdillyCustomer entity) {
		customerDAO.update(entity);
	}

	@Override
	public void delete(CasdillyCustomer entity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Boolean insert(LinkedList<CasdillyCustomer> customerList) {
		return customerDAO.insertBatch(customerList);
	}

	@Override
	public List<Map<String, String>> listByHetongSerial(Page p) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
		return 		customerDAO.listByHetongSerial(p);
	}

	@Override
	public Integer countByHetongSerial(CasdillyCustomer customer) {
		return 		customerDAO.countByHetongSerial(customer);
	}

	@Override
	public List<Map<String, String>> listByHetongSerial(CasdillyCustomer customer) {
		return 		customerDAO.listByHetongSerial(customer);
	}

	@Override
	public CasdillyCustomer findByFenchangIDAndUserNameAndPhone(CasdillyCustomer casdillyCustomer) {
		return customerDAO.findByFenchangIDAndUserNameAndPhone(casdillyCustomer);
	}

	@Override
	public List<CasdillyCustomer> listByPhone(CasdillyCustomer ct) {
 		return customerDAO.listByPhone(ct);
	}

	@Override
	public CasdillyCustomer getCustomerAndScanData(String customerID) {
 		return customerDAO.getCustomerAndScanData(customerID);
	}

	@Override
	public CasdillyCustomer findByFenchangIDAndUserName(CasdillyCustomer casdillyCustomer) {
		 return customerDAO.findByFenchangIDAndUserName(casdillyCustomer);
	}

	@Override
	public List<Map<String, String>> listByIDs(String ids) throws Exception {
 		return customerDAO.listByIDs(ids);
	}

	@Override
	public void updateCustomerExportStatus(List<Map<String, String>> list, Integer integer, Date date) {
		customerDAO.updateCustomerExportStatus(list,integer,date);
	}

 

	@Override
	public List<CasdillyScanData> listScandataByID(Page p) {
 		return customerDAO.listScandataByID( p) ;
	}
	
	
	@Override
	public List<CasdillyScanData> listScandataByCustomerID(String customerID) {
 		return customerDAO.listScandataByCustomerID( customerID) ;
	}
	

	@Override
	public Integer countScandataByID(String customerID) {
 		return customerDAO.countScandataByID( customerID);
	}

	@Override
	public void updateScandata(CasdillyScanData csd) {
		customerDAO.updateScandata( csd);
		
	}

	@Override
	public void updateQrCodeInfo(CasdillyCustomer casdillyCustomer) {
		
		customerDAO.updateQrCodeInfo( casdillyCustomer);
	}

	@Override
	public CasdillyCustomer findCustomerNameById(String customerID) {
 		return customerDAO.findCustomerNameById( customerID);
	}

	@Override
	public void updateCustomerOpenID(CasdillyCustomer customer) {
		customerDAO.updateCustomerOpenID( customer);
	}

	@Override
	public List<CasdillyCustomer> listBywxOpenid(String wxOpenid) {
 		return customerDAO.listBywxOpenid( wxOpenid);
	}

	@Override
	public List<CasdillyCustomer> hodoListByHetongSerial(CasdillyCustomer customer) {
 		return customerDAO.hodoListByHetongSerial(customer);
	}

	@Override
	public List<CasdillyCustomer> hodoListByIDs(String ids) {
		return customerDAO.hodoListByIDs(ids);
	}

	@Override
	public void delCustomer(String customerID,String loginID) {
		CasdillyCustomer casdillyCustomer = new CasdillyCustomer();
		casdillyCustomer.setCustomerID(customerID);
	 
		ArrayList<CasdillyCustomer> paramList = new ArrayList<CasdillyCustomer>();
		paramList.add(casdillyCustomer);
		
		HashMap<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("list", paramList);
		paramMap.put("deleterID", loginID);
		paramMap.put("deleteTime", new Date());
		
		
		 customerDAO.updateDelInfoByCcustomerList(paramMap);
 		
	}


}
